import { addLayer, registerMapLegend, type LineStyle } from '@/map'
import { SegmentLayer } from '../util/segment'
import { routingSegmentIndex } from './routing-index'

const routingStyle: LineStyle = {
  lineColor: '#f8e0e4',
  lineWidth: 0.5,
  lineOpacity: 1.0
}

export let routingLayer: SegmentLayer

function initRoutingLayer() {
  routingLayer = new SegmentLayer({
    id: 'Entity:Routing',
    name: '飞行路线',
    style: routingStyle,
    segment: routingSegmentIndex.segments(),
    minZoom: 4.5
  })
  addLayer(routingLayer)
  // const layer = new BaseLineLayer<Routing>(
  //   {
  //     id: 'Entity:Routing',
  //     name: '飞行路线',
  //     style: routingStyle,
  //     getFeature: (r: Routing) => routing2Feature(r, null),
  //     minZoom: 4.5
  //   },
  //   lst
  // )
  // addLayer(layer)
  // routingLayer = layer
}

function initRoutingLayerLegend() {
  registerMapLegend({
    name: '飞行路线',
    visible() {
      return routingLayer.visible
    },
    setVisible(ok) {
      routingLayer.visible = ok
    }
  })
}

export function initMap() {
  initRoutingLayer()
  initRoutingLayerLegend()
}
